#include <iostream>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
using namespace std;

int main()
{
        pid_t id=fork();
        if(id==0)
        {
            //child
            int cnt=500;
            while(cnt--)
            {
                cout<<"I am child process,my pid: "<<getpid()<<" cnt: "<<cnt<<endl;
                sleep(1);
            }
            exit(0);
        }
       // father
        int status=0;
        pid_t rid=waitpid(id,&status,0);
        cout<<"child quit info, rid: "<< rid<<" exit code: "<<
            ((status>>8)&0xff)<<" exit signal: "<<(status&0x7f) <<" core dumped: "
            << ((status>>7)&1)<<endl;
   // int a = 10 / 0;

    return 0;
}


